package com.schx.budget.controller

import com.schx.budget.pojo.BudgetTarget
import com.schx.budget.service.BudgetService
import com.schx.budget.service.BudgetTargetService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile

@Controller
class BudgetTargetController {

    @Autowired
    lateinit var budgetTargetService: BudgetTargetService

    @GetMapping("/getTargetList")
    @ResponseBody
    fun getTargetList(type: String, orgid: String): List<BudgetTarget> {
        return budgetTargetService.getTargetList(type, orgid)
    }

    @GetMapping("/getCostTargetList")
    @ResponseBody
    fun getCostTargetList(type: String, orgid: String): List<BudgetTarget> {
        return budgetTargetService.getCostTargetList(type, orgid)
    }

    /**
     * 保存项目目标预算
     */
    @PostMapping("/save")
    @ResponseBody
    fun save(@RequestBody list: List<BudgetTarget>): Int {
        var num = 0
        list.forEach {
            num += budgetTargetService.save(it)
        }
        return num
    }

    @GetMapping("/getProfits")
    @ResponseBody
    fun getProfits(orgid: String): MutableMap<String, Any?>{
        return budgetTargetService.getProfits(orgid)
    }

    @GetMapping("/delTarget")
    @ResponseBody
    fun delTarget(orgid: String, id: String): Int {
        return budgetTargetService.delTarget(orgid, id)
    }

}
